<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js课堂练习</title>
</head>
<body>
<img id="light" src="off.gif"> <br>
<input type="button" value="点亮" >
<input type="button" value="熄灭" >
<br> <br>
<input type="text" onfocus="lower()" onblur="upper()"  id="name" value="BRIUP">
<br> <br>
<input type="checkbox" name="hobby"> 电影
<input type="checkbox" name="hobby"> 旅游
<input type="checkbox" name="hobby"> 游戏
<br>
<input type="button" value="全选" onclick="checkedAll()">
<input type="button" value="反选" onclick="reverse()">
<script>
  // 点亮灯泡
  // 获取两个button的元素，修改对应的img的src的值
  var oImg = document.getElementById("light");
  // 获取所有的input取前两个
  var oInputs = document.getElementsByTagName("input");
  var oBtnOn = oInputs[0];
  var oBtnOff = oInputs[1];
  // 绑定事件
  oBtnOn.onclick = function(){
    oImg.src = "on.gif";
  }
  oBtnOff.onclick = function(){
    oImg.src = "off.gif";
  }


  //输入框获取与失去焦点
  var oText = document.getElementById("name");
  function lower(){
    oText.value = oText.value.toLowerCase();
  }
  function upper(){
    oText.value = oText.value.toUpperCase();
  }


//复选框全选与反选
  var ocheckBox = document.getElementsByName("hobby");
  function  checkedAll(){
    ocheckBox.forEach((value)=>{
     value.checked = true;
    });
  }

  function reverse(){
    ocheckBox.forEach((value)=>{
      value.checked = !value.checked;
    });

  }

</script>
</body>
</html>